/**
* V1版本：需要自己添加依赖及触发
*/
class Dep{
  constructor() {
    // 唯一依赖仅更新一次
    this.subscribers = new Set()
  }
  addEffect(effect) {
    this.subscribers.add(effect)
  }
  notify() {
    this.subscribers.forEach(effect => {
      effect()
    })
  }
}

const dep = new Dep;
const info={count:100}
function doubleCount() {
  console.log(info.count*2);
}

function powerCount() {
  console.log(info.count * info.count);
}
// 收集依赖，把相应的依赖更新添加进去
dep.addEffect(doubleCount)
dep.addEffect(powerCount)
info.count++
// 触发依赖
dep.notify()
